package com.tadpole.music.adapter.home;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.tadpole.music.R;
import com.tadpole.music.adapter.base.BaseAdapter;
import com.tadpole.music.bean.home.ClockInRankBean;
import com.tadpole.music.holder.base.BaseViewHolder;
import com.tadpole.music.holder.base.NoDataEmpty;
import com.tadpole.music.holder.home.RankViewHolder;

/**
 * 排行榜
 * Created By 孙岩
 * on 2020/12/9
 */
public class RankAdapter extends BaseAdapter {
    private Activity activity;
    private RankViewHolder rankViewHolder;
    private ClockInRankBean.DataBean dataBean;

    public RankAdapter(Activity activity, ClockInRankBean.DataBean dataBean) {
        this.activity = activity;
        this.dataBean = dataBean;
    }

    @Override
    public BaseViewHolder createRelHolder(ViewGroup parent, int viewType) {
        if (dataBean == null || dataBean.getList().size() == 0) {
            String empty = "NO_RANK";
            LayoutInflater layoutInflater = LayoutInflater.from(activity);
            View inflate = layoutInflater.inflate(R.layout.item_no_data, parent, false);
            NoDataEmpty noDataEmpty = new NoDataEmpty(inflate, empty);
            return noDataEmpty;
        } else {
            rankViewHolder = new RankViewHolder(activity, LayoutInflater.from(activity).inflate(R.layout.item_rank, parent, false),dataBean);
            return rankViewHolder;
        }

    }

    @Override
    public int getRelItemCount() {
        return dataBean == null || dataBean.getList().size() == 0 ? 1 : dataBean.getList().size();
    }

    @Override
    public void setOnItemClickListener(OnItemClickListener listener) {

    }

    @Override
    public void setOnChildClickListener(OnChildClickListener listener) {

    }

    @Override
    public void setOnLongClickListener(OnLongClickListener listener) {

    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder holder, int position) {
        holder.init(position - mHeadViews.size());
    }
}
